package outoforder.leetcode;

import org.junit.Test;

/**
 * @author shhjiang_001
 * @create 2020-07-01 21:11
 */
public class Solution309 {

    public int maxProfit(int[] prices) {
        int[][] ints = new int[prices.length][2];
        ints[0][1] = -prices[0];
        ints[0][0] = 0;
        for (int i = 1; i < prices.length; i++) {
            int m = 0;
            if (i-2>=0){
                m = ints[i-2][0];
            }
            ints[i][0] = Math.max(ints[i-1][0],ints[i-1][1]+prices[i]);
            ints[i][1] = Math.max(ints[i-1][1],m-prices[i]);
        }

        return ints[prices.length-1][0];
    }
    @Test
    public void test(){
        System.out.println(maxProfit(new int[]{1, 2, 3, 0, 2}));
    }
}
